import 'dart:collection';
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter_scan_tool/models/tool_kit.dart';


//仓库信息
class StorageInfo {
  String id;
  String storageName; //仓库名称
  List<ToolKit>? toolKitList; //仓库下关联的工具柜列表
  StorageInfo({
    required this.id,
    required this.storageName,
    this.toolKitList,
  });

  StorageInfo copyWith({
    String? id,
    String? storageName,
    List<ToolKit>? toolKitList,
  }) {
    return StorageInfo(
      id: id ?? this.id,
      storageName: storageName ?? this.storageName,
      toolKitList: toolKitList ?? this.toolKitList,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'storageName': storageName,
      'toolKitList': toolKitList?.map((x) => x.toMap()).toList()??[],
    };
  }

  factory StorageInfo.fromMap(Map<String, dynamic> map) {
    return StorageInfo(
      id: map['id'] ?? '',
      storageName: map['storageName'] ?? '',
      toolKitList: List<ToolKit>.from(
          map['toolKitList']?.map((x) => ToolKit.fromJson(json.encode(x)))),
    );
  }

  String toJson() => json.encode(toMap());

  factory StorageInfo.fromJson(String source) =>
      StorageInfo.fromMap(json.decode(source));

  @override
  String toString() =>
      'StorageInfo(id: $id, storageName: $storageName, toolKitList: $toolKitList)';

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is StorageInfo &&
        other.id == id &&
        other.storageName == storageName &&
        listEquals(other.toolKitList, toolKitList);
  }

  @override
  int get hashCode => id.hashCode ^ storageName.hashCode ^ toolKitList.hashCode;
}
